<template>
  <button @click="change">切换组件</button>
  <keep-alive>
    <component :is="current"></component>
  </keep-alive>
</template>

<script>
import Test1 from "../otherComonents/keepalive1.vue";
import Test2 from "../otherComonents/keepalive2.vue";
export default {
  data() {
    return {
      current: "Test1",
    };
  },
  components: {
    Test1,
    Test2,
  },
  methods: {
    change() {
      if (this.current === "Test1") {
        this.current = "Test2";
      } else {
        this.current = "Test1";
      }
    },
  },
};
</script>

<style>
</style>